// pages/user/teachers/teachers.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        hasMore: true,
        data: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.onPullDownRefresh();
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.loadData(1).finally(() => {
            wx.stopPullDownRefresh();
        });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        if (!this.data.hasMore) return;

        const page = this.data.page + 1;
        this.loadData(page);
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        const image = "";
        return {
            imageUrl: image,
            path: this.route
        }
    },

    // 加载商城列表
    loadData: function(page = 1) {
        return wx.http.get('api/curriculum.Lecturer/getlist', {
            page: page,
            sortType: this.data.goodsType,
            sortPrice: this.data.sortPrice,
            search: this.data.keyword,
            course_id: '',
            category_id: ''
        }).then((res) => {
            res = res.data.data.list;
            const hasMore = res.data.length >= res.per_page;
            const data = page > 1 ? this.data.data.concat(res.data) : res.data;
            this.setData({
                page: page,
                hasMore: hasMore,
                data: data,
            });
            return res.data;
        }, (err) => {
            console.warn("api/curriculum.Lecturer/getlist", err)
        });
    },
})
